import sun.reflect.generics.tree.Tree;

import javax.swing.tree.TreeNode;

public class BinaryTree {
//二叉树的基本操作
    class TreeNode{
        char val;
        public TreeNode left;
        public TreeNode right;
    }
    public int nodeSize;

    public int size(TreeNode root)
    {
        if(root == null) return 0;
        nodeSize++;
        size(root.left);
        size(root.right);
        return nodeSize;
    }

    public int size2(TreeNode root)
    {
        if (root == null) return 0;
        return size2(root.left) + size2(root.right) + 1;
    }

    public int leafSize;
    public int getLeafNodeCount(TreeNode root)
    {
        if(root == null) return 0;
        if(root.left == null && root.right == null) leafSize++;
        getLeafNodeCount(root.left);
        getLeafNodeCount(root.right);

        return leafSize;
    }

    public int getLeafNodeCount2(TreeNode root)
    {
        if(root == null) return 0;
        if(root.left == null && root.right == null) return 1;
        return getLeafNodeCount2(root.left) + getLeafNodeCount2(root.right);
    }

    public int getKLeveLNodeCount(TreeNode root, int k)
    {
        if(root == null)return 0;
        if(k == 1) return 1;
        return getKLeveLNodeCount(root.left, k - 1) + getKLeveLNodeCount(root.right, k - 1);
    }

    int getHeight(TreeNode root)
    {
        if(root == null) return 0;
        int leftHeight = getHeight(root.left);
        int rightHeight = getHeight(root.right);

        return Math.max(leftHeight, rightHeight) + 1;
    }

    TreeNode find(TreeNode root, char val)
    {
        if(root == null) return null;

        if(root.val == val) return root;

        TreeNode leftTree = find(root.left, val);
        if(leftTree != null) return leftTree;

        TreeNode rightTree = find(root.right, val);
        if(rightTree != null) return rightTree;

        return null;
    }
}
